package cn.math.appmath.action;

import org.apache.struts2.ServletActionContext;

import cn.math.appmath.bean.NoticBean;
import cn.math.appmath.biz.NoticBiz;
import cn.math.appmath.entity.Notic;

import com.opensymphony.xwork2.ActionSupport;

public class NoticAction extends ActionSupport {
	private static final long serialVersionUID = -4565898601842133546L;
	private NoticBiz noticBiz;
	private NoticBean noticBean;
	private Notic notic;
	private String message;
	private Integer[] nos;
	private Integer type;
	
	public String findNotic(){
		Integer page = Integer.parseInt(ServletActionContext.getRequest().getParameter("page"));
		String param = ServletActionContext.getRequest().getParameter("param");
		Integer messageType = Integer.parseInt(ServletActionContext.getRequest().getParameter("type"));
		noticBean = noticBiz.findAll(page, param, messageType);
		if(messageType == 1)
			return "message";
		else
			return "notic";
	}
	
	public String findById(){
		Integer id = Integer.parseInt(ServletActionContext.getRequest().getParameter("id"));
		String typeStr = ServletActionContext.getRequest().getParameter("type");	
		notic = noticBiz.findById(id);
		if("".equals(typeStr) || typeStr == null)
			return SUCCESS;
		Integer messageType = Integer.parseInt(typeStr);
		if(messageType == 1)
			return "message";
		else
			return "notic";
	}
	
	public String noticforward(){
		message = "";
		return SUCCESS;
	}
	
	/**
	 * 后台查看信息公告或重要通知列表
	 * @return
	 */
	public String backFindNotic(){
		int page = 0;
		String pageStr = ServletActionContext.getRequest().getParameter("page");
		String param = ServletActionContext.getRequest().getParameter("param");
		String messageType = ServletActionContext.getRequest().getParameter("type");
		if(pageStr != null && !pageStr.equals(""))
			page = Integer.parseInt(pageStr);
		if(param == null || param.equals(""))
			param = "backward";
		if(messageType != null && !messageType.equals(""))
			type = Integer.parseInt(messageType);
		noticBean = noticBiz.findAll(page, param, type);
		if(type == 1)
			return "message";
		else
			return "notic";
	}
	
	/**
	 * 删除单条记录
	 * @return
	 */
	public String delNotic(){
		type = Integer.parseInt(ServletActionContext.getRequest().getParameter("type"));
		Integer nno = new Integer(ServletActionContext.getRequest().getParameter("nno"));
		if(noticBiz.delete(nno)){
			return SUCCESS;
		}else{
			message = "删除信息公告或重要通知信息失败";
			return INPUT;
		}
	}
	
	/**
	 * 批量删除记录
	 * @return
	 */
	public String batchDeleteNotic(){
		type = Integer.parseInt(ServletActionContext.getRequest().getParameter("type"));
		if(noticBiz.batchDelete(nos)){
			return SUCCESS;
		}else{
			message = "删除信息公告或重要通知信息失败";
			return INPUT;
		}
	}
	
	/**
	 * 保存信息公告或重要通知
	 * @return
	 */
	public String saveNotic(){
		if(noticBiz.save(notic)){
			message = "保存信息公告或重要信息成功";
			return SUCCESS;
		}
		message = "保存信息公告或重要信息失败";
		return INPUT;
	}
	
	public NoticBean getNoticBean() {
		return noticBean;
	}

	public void setNoticBean(NoticBean noticBean) {
		this.noticBean = noticBean;
	}

	public void setNoticBiz(NoticBiz noticBiz) {
		this.noticBiz = noticBiz;
	}

	public Notic getNotic() {
		return notic;
	}

	public void setNotic(Notic notic) {
		this.notic = notic;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Integer[] getNos() {
		return nos;
	}

	public void setNos(Integer[] nos) {
		this.nos = nos;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}
}
